package com.ruoyi.keep.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.keep.domain.FitnessGym;
import com.ruoyi.keep.service.IFitnessGymService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健身馆Controller
 * 
 * @author zqd
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/keep/gym")
public class FitnessGymController extends BaseController
{
    @Autowired
    private IFitnessGymService fitnessGymService;

    /**
     * 查询健身馆列表
     */
    @PreAuthorize("@ss.hasPermi('keep:gym:list')")
    @GetMapping("/list")
    public TableDataInfo list(FitnessGym fitnessGym)
    {

        List<FitnessGym> list = fitnessGymService.selectFitnessGymList(fitnessGym);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出健身馆列表
     */
    @PreAuthorize("@ss.hasPermi('keep:gym:export')")
    @Log(title = "健身馆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FitnessGym fitnessGym)
    {
        List<FitnessGym> list = fitnessGymService.selectFitnessGymList(fitnessGym);
        ExcelUtil<FitnessGym> util = new ExcelUtil<FitnessGym>(FitnessGym.class);
        util.exportExcel(response, list, "健身馆数据");
    }

    /**
     * 获取健身馆详细信息
     */
    @PreAuthorize("@ss.hasPermi('keep:gym:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fitnessGymService.selectFitnessGymById(id));
    }

    /**
     * 新增健身馆
     */
    @PreAuthorize("@ss.hasPermi('keep:gym:add')")
    @Log(title = "健身馆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FitnessGym fitnessGym)
    {
        return toAjax(fitnessGymService.insertFitnessGym(fitnessGym));
    }
//把用户经纬度存进缓存
    @PreAuthorize("@ss.hasPermi('keep:gym:add')")
    @Log(title = "健身馆", businessType = BusinessType.INSERT)
    @PostMapping("/{longitude}/{latitude}/{userId}")
    public List<FitnessGym> insertuserredis(@PathVariable("longitude") Double longitude,
            @PathVariable("latitude") Double latitude,
            @PathVariable("userId") Integer userid)
    {
        List<FitnessGym> list = fitnessGymService.insertuserRedis(longitude, latitude, userid);
        return list;
    }




//    根据key去缓存查健身馆数据
@PreAuthorize("@ss.hasPermi('keep:gym:add')")
@Log(title = "健身馆", businessType = BusinessType.INSERT)
@GetMapping("/gymid/key")
public FitnessGym selectgynmidRedis(String gymid) {
    FitnessGym fitnessGym = fitnessGymService.selectgynmidRedis(gymid);
    return fitnessGym;
}


//    根据名字去缓存查健身馆数据
    @PreAuthorize("@ss.hasPermi('keep:gym:add')")
    @Log(title = "健身馆", businessType = BusinessType.INSERT)
    @GetMapping("/gymid/name")
    public List<FitnessGym> findBynameRedis(String gymName) {
        List<FitnessGym> fitnessGyms = fitnessGymService.selectByname(gymName);
        return fitnessGyms;
    }




    /**
     * 修改健身馆
     */
    @PreAuthorize("@ss.hasPermi('keep:gym:edit')")
    @Log(title = "健身馆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FitnessGym fitnessGym)
    {
        return toAjax(fitnessGymService.updateFitnessGym(fitnessGym));
    }

    /**
     * 删除健身馆
     */
    @PreAuthorize("@ss.hasPermi('keep:gym:remove')")
    @Log(title = "健身馆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fitnessGymService.deleteFitnessGymByIds(ids));
    }
}
